<?php 

// ditulis oleh  @supangat_oy

defined('BASEPATH') OR exit('No direct script access allowed');
defined('SP_BUY') OR exit('APLIKASI EROR SILAHKAN HUBUNGI 083873272419');


class Jawaban extends CI_Controller {
	var $judul;
	function __construct(){
		parent::__construct();
		$this->m_config->cek_sesi();
		$this->judul="Hasil Pengerjaan Siswa";
	}
	public function json_list($id_ujian)
	{
		$this->load->library("Datatables");

		$this->datatables->select("*, u.Urut as IdSiswaUjian");
		$this->datatables->from("cbt_siswa s");
		$this->datatables->join("cbt_nilai n","n.XNomerUjian = s.XNomerUjian");
		$this->datatables->join("cbt_siswa_ujian u","u.XIdUjian = n.XIdUjian AND u.XNomerUjian = n.XNomerUjian AND n.XTokenUjian = u.XTokenUjian");
		$this->datatables->where("u.XIdUjian",$id_ujian);


		$this->datatables->add_column('lihat', '<a class="btn blue darken-2" href="'. base_url('admin/jawaban/lihat') .'/$1">Lihat jawaban</a>', 'IdSiswaUjian');
		echo $this->datatables->generate();
	}
	public function index($idUjian=0)
	{
		$data['id']=$idUjian;
		$data['title']='Kelola '.$this->judul;

		$this->load->view('head_meta',$data);
		$this->load->view('admin/header',$data);
		
		$this->load->view('admin/jawaban/list',$data);
		$this->load->view('admin/footer',$data);
	}

	public function lihat($Urut)
	{
		// get data ujian dan data umumu lainya
		$this->db->select("*, u.Urut as IdSiswaUjian,s.XNamaKelas as KelasSiswa");
		$this->db->from("cbt_siswa s");
		$this->db->join("cbt_siswa_ujian u","u.XNomerUjian = s.XNomerUjian");
		$this->db->join("cbt_ujian  uj","uj.Urut = u.XIdUjian");
		$this->db->join("cbt_paketsoal  ps","uj.XKodeSoal = ps.XKodeSoal");
		$this->db->where("u.Urut",$Urut);

		$data['ujian']=$this->db->get()->row();	


		// get data jawaban dan soal
		$this->db->select("j.*,s.*,j.Urut as Nomer,j.XRagu as Ragu");
		$this->db->from("cbt_jawaban j")->where([
			'j.XIdUjian' => $data['ujian']->XIdUjian,
			'j.XNomerUjian' => $data['ujian']->XNomerUjian,
		]);
		$this->db->join("cbt_siswa_ujian sj","sj.XIdUjian =  j.XIdUjian AND sj.XNomerUjian = j.XNomerUjian");
		$this->db->join("cbt_ujian u","sj.XIdUjian = u.Urut");
		$this->db->join("cbt_soal s",'j.XNomerSoal = s.XNomerSoal AND u.XKodeSoal = s.XKodeSoal');
		$this->db->order_by("j.Urut","ASC");

		$data['jawaban']=$this->db->get()->result_array();	


		$data['title']='Lihat Jawaban Siswa';
		$this->load->view('head_meta',$data);
		$this->load->view("admin/print_header",$data);
		$this->load->view('admin/jawaban/lihat',$data);
		$this->load->view("admin/print_footer",$data);
	}
}
